<?php
/*
* @version		$Id: helper.php 14401 2010-01-26 14:10:00Z louis $
* @package		Joomla
* @copyright	Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

class modDownloadHelper{
	
			function getParent(){
				$db = JFactory::getDBO();
				$query = "SELECT id,name,parent FROM #__k2_categories WHERE parent = 2 ";
				$db->setQuery($query);
				$rows = $db->loadObjectList();
				$parent =array();
				if($rows){
					foreach ($rows as $row){
						$id = $row->id;	
						$parent[] = $id;
						}
					}
					return $parent;
				}
			function getChident(){
				$db = JFactory::getDBO();
				$p = modDownloadHelper::getParent();
				$pa = @implode(',',$p);
				$query = "SELECT id,name,parent FROM #__k2_categories WHERE parent IN ({$pa}) ";
				$db->setQuery($query);
				$rows = $db->loadObjectList();
				$chident =array();
				if($rows){
					foreach ($rows as $row){
						$id = $row->id;	
						$chident[] = $id;
						}
					}
					return $chident;
				}
			function getData(){
				$db = JFactory::getDBO();
				$paid = modDownloadHelper::getParent();
				$chilid = modDownloadHelper::getChident();
				$paid = @implode(',',$paid);
				$chilid = @implode(',',$chilid);
				$query = "SELECT * FROM #__k2_items WHERE catid IN ({$paid}) OR catid IN ({$chilid}) OR catid = 2  
				ORDER BY id DESC LIMIT 0,8";
				$db->setQuery($query);
				$rows = $db->loadObjectList(); 
				return $rows;
			}
		
	}